﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using ResultModel.Web.MSDN;
using CSRedis;
using DataSave.RedisClient;
using Newtonsoft.Json;


namespace DataSave.Web.MSDN
{
    public class ForRedisService : IForRedisService
    {
        private CSRedisClient _client { get; set; }
        public ForRedisService(IRedisService Client)
        {
            _client = Client.CSRedisDB(RedisDb.DB2);
        }
        public async Task SaveCateAsync(IList<Category> input)
        {

            List<string> ls = new List<string>();
            int level = 0;
            foreach (var item in input)
            {
                if(level == 0)
                {
                    level = item.Level;
                }
                string st = JsonConvert.SerializeObject(item);
                ls.Add(st);
            }
           await _client.LPushAsync("CateListIn"+level, ls.ToArray());
        }
    }
}
